import { createStore } from 'vuex'
import {  headerMenuSingle, menu} from '@/Json/menu'
import {
    getStore,
    setStore,
    clearStore
  } from '@/utils/store'
const store = createStore({
    state(){
        return {
            title:'vue3管理系统',
            userInfo:{},
            menuType:''|| getStore({ name: 'menuType'}),
            showMenuArr:[]||getStore({ name: 'showMenuArr'}),
            headerActive:getStore({ name: 'headerActive'})||'1',
			token:''||getStore({ name: 'token'})
        }
    },
    mutations:{
        setMenuType(state,type){
            const {menuType ,data} = type
            state.menuType = menuType
            if(menuType === 'double'){
                state.showMenuArr = data
            }else if(menuType === 'single'){
                state.showMenuArr = data
            }
            setStore({
                name: 'menuType',
                content: menuType,
                type: 'session'
            })
            setStore({
                name: 'showMenuArr',
                content: state.showMenuArr,
                type: 'session'
            })
        },
        setUserInfo(state,type){
            state.menuType = type
            setStore({
                name: 'userInfo',
                content: type,
                type: 'session'
            })
        },
        setHeaderActive(state,type){
            state.headerActive = type
            setStore({
                name: 'headerActive',
                content: state.headerActive,
                type: 'session'
            })
        },
		setToken(state,type){
			state.token = type
			setStore({
			    name: 'token',
			    content: state.token,
			    type: 'session'
			})
		},
        setClearStore(){
            clearStore({
                type:'sessionStorage'
            })
        }
    },
    actions:{

    },
    getters: {
        // 获取  菜单 方法
        getMenu(state) {
            state.showMenuArr = getStore({ name: 'showMenuArr'})
            return state.showMenuArr;
        },
        getUserInfo(state) {
            state.userInfo = getStore({ name: 'userInfo'})
            return state.userInfo;
        },
        getHeaderActive(state){
            state.headerActive = getStore({ name: 'headerActive'})||'1'
            return state.headerActive;
        },
    },
})

export default store